﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PKURG.CostSplit.SyncService.DAL
{
    class DB_CostSplite
    {
        internal List<SyncPlan> GetPlanList()
        {
            CostSplitEntities context = new CostSplitEntities();
            return context.SyncPlan.OrderBy(x => x.OrderId).ToList();
        }

        internal void Record(SyncPlan item, ReturnInfo rInfo)
        {
            CostSplitEntities context = new CostSplitEntities();
            context.SyncHistory.AddObject(new SyncHistory()
            {
                 Id=Guid.NewGuid(),
                IsAuto = item.IsJustIn,
                Name = item.Name,
                ExeTime = DateTime.Now,
                Result = rInfo.ex == null ? "完成" : string.Format("{0}\r\n{1}", rInfo.ex.Message, rInfo.ex.StackTrace),
                StartUser = item.JustInUser
            });

            SyncPlan plan = context.SyncPlan.Where(x => x.Id == item.Id).SingleOrDefault();
            plan.JustInUser = "";
            plan.IsJustIn = 0;
            plan.LastExeTime = DateTime.Now;

          //  context.SaveChanges();
        }
    }
}
